package com.zhonghui.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zhonghui.mes.domain.vo.MesProductInspectorVo;
import com.zhonghui.response.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhonghui.common.annotation.Log;
import com.zhonghui.common.core.controller.BaseController;
import com.zhonghui.common.enums.BusinessType;
import com.zhonghui.mes.domain.MesProductInspector;
import com.zhonghui.mes.service.IMesProductInspectorService;
import com.zhonghui.common.utils.poi.ExcelUtil;
import com.zhonghui.common.core.page.TableDataInfo;

/**
 * 产品检验Controller
 * 
 * @author zhonghui
 * @date 2022-05-23
 */
@Api(tags ="制造执行MES-产品检验（质量追溯/质量报告）")
@RestController
@RequestMapping("/mes/productInspector")
public class MesProductInspectorController extends BaseController
{
    @Autowired
    private IMesProductInspectorService mesProductInspectorService;

    /**
     * 查询产品检验列表
     */
    @ApiOperation("查询产品检验（质量追溯/质量报告）列表")
    @GetMapping("/list")
    public TableDataInfo<List<MesProductInspectorVo>> list(MesProductInspectorVo mesProductInspectorVo)
    {
        startPage();
        List<MesProductInspectorVo> list = mesProductInspectorService.selectMesProductInspectorList(mesProductInspectorVo);
        return getDataTable(list);
    }

    /**
     * 导出产品检验列表
     */
    @ApiOperation("导出产品检验（质量追溯/质量报告）列表")
    @Log(title = "产品检验", businessType = BusinessType.EXPORT)

    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProductInspectorVo mesProductInspectorVo)
    {
        List<MesProductInspectorVo> list = mesProductInspectorService.selectMesProductInspectorList(mesProductInspectorVo);
        ExcelUtil<MesProductInspectorVo> util = new ExcelUtil<MesProductInspectorVo>(MesProductInspectorVo.class);
        util.exportExcel(response, list, "产品检验数据");

    }

    /**
     * 获取产品检验详细信息
     */
    @ApiOperation("获取产品检验（质量追溯/质量报告）详细信息")
    @GetMapping(value = "/{id}")
    public BaseResult<MesProductInspectorVo> getInfo(@PathVariable("id") Long id)
    {
        return BaseResult.success(mesProductInspectorService.selectMesProductInspectorById(id));
    }

    /**
     * 新增产品检验
     */
    @ApiOperation("新增产品检验")
    @Log(title = "产品检验", businessType = BusinessType.INSERT)
    @PostMapping
    public BaseResult<Integer> add(@RequestBody MesProductInspector mesProductInspector)
    {
        return BaseResult.success(mesProductInspectorService.insertMesProductInspector(mesProductInspector));
    }

    /**
     * 修改产品检验
     */
    @ApiOperation("修改产品检验")
    @Log(title = "产品检验", businessType = BusinessType.UPDATE)
    @PutMapping
    public BaseResult<Integer> edit(@RequestBody MesProductInspector mesProductInspector)
    {
        return BaseResult.success(mesProductInspectorService.updateMesProductInspector(mesProductInspector));
    }

    /**
     * 删除产品检验
     */
    @ApiOperation("删除产品检验")
    @Log(title = "产品检验", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public BaseResult<Integer> remove(@PathVariable Long[] ids)
    {
        return BaseResult.success(mesProductInspectorService.deleteMesProductInspectorByIds(ids));
    }
}
